package Animal;

public class TestAnimal {
    public static void main(String[] args) {
        Cat cat = new Cat("新鲜哥");
        Dog dog = new Dog("小七");
// 向上转型
        Animal animal = cat;
        animal.eat();
        animal = dog;
        animal.eat();
        if(animal instanceof Cat){  //结果为false，不执行
            cat = (Cat)animal;
            cat.mew();
        }
        if(animal instanceof Dog){  //结果为true，执行
            dog = (Dog)animal;
            dog.bark();
        }
    }
}
//输出结果
//新鲜哥吃猫粮
//小七吃狗粮
//小七汪汪

class B {
    public B() {
// do nothing
        func();
    }
    public void func() {
        System.out.println("B.func()");
    }
}
class D extends B {
    private int num = 1;
    @Override
    public void func() {
        System.out.println("D.func() " + num);
    }
}
class Test1 {
    public static void main(String[] args) {
        D d = new D();
    }
}
// 执行结果
//D.func() 0



